package cn.iocoder.yudao.module.ad.effect.service;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.pojo.vo.UserSimpleVO;
import cn.iocoder.yudao.framework.business.basic.service.impl.MemberScopeService;
import cn.iocoder.yudao.module.ad.effect.convert.AdEffectRecordConvert;
import cn.iocoder.yudao.module.ad.effect.dal.dataobject.AdEffectRecordDO;
import cn.iocoder.yudao.module.ad.effect.dal.mysql.AdEffectRecordMapper;
import cn.iocoder.yudao.module.ad.effect.vo.AdminAdEffectRecordQueryDTO;
import cn.iocoder.yudao.module.ad.effect.vo.AdminAdEffectRecordVO;
import cn.iocoder.yudao.module.api.member.user.MemberUserApi;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Collection;
import java.util.Map;

/**
 * 广告效果记录 Service 实现类
 *
 * @author 山野羡民
 */
@Slf4j
@Service
@Validated
public class AdminAdEffectRecordServiceImpl extends MemberScopeService<AdEffectRecordDO, AdminAdEffectRecordVO, AdminAdEffectRecordQueryDTO> implements AdminAdEffectRecordService {
    @Resource
    private AdEffectRecordMapper adEffectRecordMapper;

    @Resource
    private MemberUserApi memberUserApi;

    @Override
    protected AdEffectRecordMapper getInjectedMapper() {
        return adEffectRecordMapper;
    }

    @Nonnull
    @Override
    protected CoreQueryWrapper<AdEffectRecordDO> buildQueryWrapper(AdminAdEffectRecordQueryDTO param) {
        CoreQueryWrapper<AdEffectRecordDO> wrapper = super.buildQueryWrapper(param);
        wrapper.eqIfPresent("scene", param.getScene());
        wrapper.eqIfPresent("type", param.getType());
        wrapper.eqIfPresent("plan_id", param.getPlanId());
        wrapper.eqIfPresent("user_id", param.getUserId());
        wrapper.orderByDesc("update_time");
        return wrapper;
    }

    @Nonnull
    @Override
    protected Map<Long, UserSimpleVO> getUserSimpleMap(Collection<Long> userIds) {
        return memberUserApi.getUserSimpleMap(userIds);
    }

    @Override
    public AdminAdEffectRecordVO convertToViewObject(AdEffectRecordDO entity) {
        return AdEffectRecordConvert.INSTANCE.convert(entity);
    }

}